package com.xm.executor;

import java.util.concurrent.*;

/**
 * @author xiaoming
 * @date 2021-03-02 0:18
 */
public class Test {
    public static void main(String[] args) {

        ExecutorService ex = Executors.newSingleThreadExecutor(); // 单个线程, 排序执行
        Executors.newFixedThreadPool(2); // 固定线程数量, 过多数据量时容易丢弃
        Executors.newCachedThreadPool(); // 响应时间高, ,数量可控, 容易OOM

        // ScheduledThreadPoolExecutor
        Executors.newScheduledThreadPool(1);
        Executors.newSingleThreadScheduledExecutor();

        /// Future
        FutureTask futureTask = (FutureTask) ex.submit(new Runnable() {
            @Override
            public void run() {
            }
        });

        try {
            futureTask.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        // Runnable
        Executors.callable(new Runnable() {
            @Override
            public void run() {

            }
        });

        // ScheduledThreadPoolExecutor
//        ScheduledThreadPoolExecutor scheduled = new ScheduledThreadPoolExecutor();
//        scheduled.scheduleAtFixedRate();
//        scheduled.scheduleWithFixedDelay();

//        public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay,long period, TimeUnit unit)


        // FutureTask
//        String.join()

        ConcurrentMap map = new ConcurrentHashMap();
    }

}
